
layui.use(['form', 'layedit', 'element'], function(){
	  var form = layui.form(), element = layui.element()
	  ,layedit = layui.layedit;
	  form.render("checkbox"); //更新全部
	  element.init();//初始化导航栏
	  //checkbox级联选择
	  form.on('checkbox(resChoose)', function(data){
		    var child = $("#sysresourcesList").find('.parentId'+$(data.elem).val());
		    var parent = $("#sysresourcesList").find('.id'+$(data.elem).attr("parentId"));
		    var parentchild = $("#sysresourcesList").find('.parentId'+parent.val());
		    child.each(function(index, item){
		      item.checked = data.elem.checked;
		    });
		    var parentcheck = false;
		    parentchild.each(function(index, item){
		    	if(item.checked){ parentcheck = true;}
		    });
		    if(parent.length)parent[0].checked = parentcheck;
		    form.render('checkbox');//更新全部
	  });
	  //全选
	  form.on('checkbox(topAllChoose)', function(data){
		    var child = $("#sysresourcesList").find('input[type="checkbox"]');
		    child.each(function(index, item){
		      item.checked = data.elem.checked;
		    });
		    form.render('checkbox');//更新全部
	  });
});
//保存用户菜单资源
function sysuserResourcesUpdate(){
	var chk_value =[]; 
	//获取选择的菜单资源
	$('input[name="idCheckbox"]:checked').each(function(){ 
		chk_value.push($(this).val()); 
	});
	$.ajax({//async : false,
			traditional: true,//参数可以传递数组ids
			type:"post",
			url:""+contextPath+"/back/sysuser/sysuserResourcesUpdate",
			data:{
					resIds:chk_value
					,userid:selectUserid
				},
			success:function(data){
				if("success"==data){
					layer.msg('角色权限保存成功！');
				}else{
					layer.msg('角色权限保存失败！');
				}
			}
	});
}